-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace espree with babel. #21853
Replace espree with babel. #21853
Conversation
These are the testing steps I'm following;
As per these steps, this works as expected! Happy to see that the code changes are minimal. Going to review the code now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good progress here, this is a nice well-scoped refactor!
We'd need to figure out a way for us to:
- use the same configuration than Gutenberg without hard-coding the path
- use the presets already available (that include JSX parsing)
After your comment about After thinking about this weirdness for a while, I realized that we don't need When using babel, we expect it to transpile new syntax to old syntax. To do so, babel parses js code and runs plugins to generate new one. In other words, babel works in these 3 steps.
As the jobs of babel/parser and babel plugins are different, we don't need to import I removed other configs and removed them. |
3855957
to
18f6f76
Compare
Good point about the transforms plugins. We do need the syntax/parser plugins for the parser to understand some syntax potentially used in Gutenberg: in our case, the With that change, I think we're good to go. |
It does bother me a bit that we need to keep an additional babel config beyond the existing ones (wordpress/babel-preset-default + gutenberg babel.config.js). What if instead of using It looks like we could reuse |
I tested your proposal about const core = require( '@babel/core' );
const parser = require( '@babel/parser' );
const code = `
try {
state?.currentUser;
} catch {
state ?? 1_000;
}
`;
try {
core.parse( code );
process.stdout.write( 'core passed\n' );
} catch ( e ) {
process.stdout.write( `core failed: ${ e }\n` );
}
try {
parser.parse( code, {
plugins: [ 'jsx' ],
sourceType: 'module',
} );
process.stdout.write( 'parser passed\n' );
} catch ( e ) {
process.stdout.write( `parser failed: ${ e }\n` );
}
try {
parser.parse( code, {
plugins: [ 'jsx', 'numericSeparator' ],
sourceType: 'module',
} );
process.stdout.write( 'parser2 passed\n' );
} catch ( e ) {
process.stdout.write( `parser2 failed: ${ e }\n` );
} Confirmed that |
18f6f76
to
ac8af64
Compare
This is nice! We also get the Gutenberg root configs for free 👏 I think we're ready to merge, the only thing left would be to document how this works in the README. Perhaps we can add a section called "Babel configuration" after the "CLI Options" that says that it takes the project-wide config, what happens if there is none, etc. What do you think? Also, could you test that documents are generated properly with the pre-commit hook? For some reason, the pre-commit hook is not working for me and I want to make sure the pre-commit hook doesn't mess up the current working directory babel uses to find the config. Testing instructions would be:
|
ac8af64
to
4dc276c
Compare
|
Good work here, @sainthkh! |
Impressive work here :) |
Just wanted to say “Thank you”, @sainthkh – I was working on some package changes including and every commit was failing, because docgen did not supporting newer ECMASript features. Not the best experience you can imagine… Today, I rebased with |
Description
Replaced
espree
withbabel
. Fixes #19952How has this been tested?
Ran
npm run docs:build
and found no change.Screenshots
N/A
Types of changes
Bug fix
Checklist: